package com.sjz.vhr.service;

import com.sjz.vhr.mapper.DepartmentMapper;
import com.sjz.vhr.model.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentService {
    @Autowired
    DepartmentMapper departmentMapper;

    //查询部门
    public List<Department> getAllDepartments() {
        //递归查询部门
        return departmentMapper.getAllDepartmentsByParentId(-1);
    }


    //添加部门
    public void addDep(Department dep) {
        //设置为能用
        dep.setEnabled(true);
        departmentMapper.addDep(dep);
    }

    //删除部门
    public void deleteDepById(Department dep){
         departmentMapper.deleteDepById(dep);
    }

    //获取所有子部门
    public List<Department> getAllDepartmentsWithOutChildren() {
        return departmentMapper.getAllDepartmentsWithOutChildren();
    }
}
